package com.lyf.baoxian.activity;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;

import com.lyf.baoxian.R;
import com.lyf.baoxian.utils.MyMethod;

/**
 * Created by 刘亚飞 on 2016/12/1.
 * 保险套餐详情界面
 */

public class ShowTaoCanActivity extends Activity implements View.OnClickListener {
    private WebView webView;
    private Button bt_buy;
    private Button bt_select;

    private String[] baoxain = new String[]{"太平洋保险","平安保险","农业保险"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_taocan);
        MyMethod.setTitle(this,"保险套餐详情");
        webView = (WebView) findViewById(R.id.web);
        bt_buy = (Button) findViewById(R.id.bt_buy);
        bt_select = (Button) findViewById(R.id.bt_select);

        bt_select.setOnClickListener(this);
        bt_buy.setOnClickListener(this);
        WebSettings settings = webView.getSettings();

        // 是否显示缩放控制器
        settings.setDisplayZoomControls(true);
        settings.setJavaScriptEnabled(true);
        //测试地址
        webView.loadUrl("http://www.ahic.com.cn/plantingRisk/45397.jhtml");
        webView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                webView.loadUrl("http://www.ahic.com.cn/plantingRisk/45397.jhtml");
                return super.shouldOverrideUrlLoading(view, request);
            }
        });
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (webView.canGoBack()) {
            webView.goBack();
        }else {
            ShowTaoCanActivity.this.finish();
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.bt_buy:
               /* Intent intent = new Intent(ShowTaoCanActivity.this,BuyTaoCanActivity.class);
                startActivity(intent);
                finish();*/
                break;

            case R.id.bt_select:
                AlertDialog.Builder builder = new AlertDialog.Builder(ShowTaoCanActivity.this);
                builder.setTitle("请选择保险");
                builder.setSingleChoiceItems(baoxain, 0, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        String text = baoxain[i];
                        bt_select.setText(text);
                        dialogInterface.dismiss();

                    }
                });
                builder.create().show();

                break;
        }
    }
}
